﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SpringStudio.Common;
using SpringStudio.DAL;
using Sdepci.InfoCode.BLL.CodeDesign;

namespace Sdepci.InfoCode.Web.CodeDesign
{
    public partial class TypeRuleEdit : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                //this.RuleModule.Attributes.Add("readonly", "readonly");
                //this.RuleModule.Attributes.Add("onfocus", "javascript:this.blur();");
                this.BindData();
            }
        }

        private void BindData()
        {
            if (this.Request.QueryString["RuleGuid"] != null && this.Request.QueryString["RuleGuid"].Trim().Length > 0)
            {
                this.lblTitle.Text += "[修改]";

                TypeRule typeRule = new TypeRule(this.Request.QueryString["RuleGuid"].Trim());
                this.RuleName.Text = typeRule.RuleName;
                this.RuleDesc.Text = typeRule.RuleDesc;
                this.RuleModule.Text = typeRule.RuleModule;
                this.RuleDemo.Text = typeRule.RuleDemo;
                this.Seq.Text = typeRule.Seq.ToString();
            }
            else
            {
                this.lblTitle.Text += "[新增]";
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            string msg = string.Empty;
            if (this.Request.QueryString["RuleGuid"] != null && this.Request.QueryString["RuleGuid"].Trim().Length > 0)
            {
                bool result = new TypeRuleManager().Update(this.Request.QueryString["RuleGuid"].Trim(), this.RuleName.Text.Trim(), this.RuleDesc.Text.Trim(), this.RuleModule.Text.Trim(), this.RuleDemo.Text.Trim(), int.Parse(this.Seq.Text.Trim()));
                msg = result ? "规则修改成功！" : "规则修改失败！";

            }
            else
            {
                bool result = new TypeRuleManager().Add(this.RuleName.Text.Trim(), this.RuleDesc.Text.Trim(), this.RuleModule.Text.Trim(), this.RuleDemo.Text.Trim(), int.Parse(this.Seq.Text.Trim()));
                msg = result ? "规则新增成功！" : "规则新增失败！";
            }

            this.ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", "<script language=\"javascript\">alert(\"" + msg + "\");document.location.href='TypeRuleList.aspx';</script>");
        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            this.Response.Redirect("TypeRuleList.aspx");
        }
    }
}
